<!--
 * @Author: your name
 * @Date: 2021-09-11 15:28:48
 * @LastEditTime: 2021-11-12 16:56:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jinfeng_up\src\components\bugRowsDialog\bugRowsDialog.vue
-->
<template>
  <div>
    <!-- 关闭弹出框 -->
    <CommonDialog
      title="绑定需求"
      width="75%"
      v-bind:dialogVisible="needDialogVisible"
      @on-change-dialogVisible="closeChange"
      class="need"
      top="10vh"
    >
      <template #body>
        <el-form class="closeForm" ref="needForm" label-width="100px" label-position="top">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="ID">
                <el-input v-model="needForm.id" @blur="toBugs"> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="解决版本" class="solutionVersion">
                <el-input type="textarea" v-model="needForm.resolutionCn" disabled class="textareaClass"> </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <template #dialog_footer>
        <el-button class="submitCancel" @click="closeCancel">取 消</el-button>
        <el-button type="primary" @click="confirmClose('closeForm')" class="submitReme" :disabled="isClick"
          >确认</el-button
        >
      </template>
    </CommonDialog>
  </div>
</template>

<script>
import CommonDialog from '@/components/commonDialog/commonDialog.vue'
import { FeedBack } from '@/api/feedBack/server'
export default {
    name: '',
    components: {
        CommonDialog
    },
    props: {},
    data() {
        return {
            isClick: true,
            needDialogVisible: false,
            feedBackNumber: '',
            needForm: {
                id: null,
                resolutionCn: ''
            }
        }
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
    // this.getCloseFeedBackReasonList()
    },
    methods: {
        // 绑定需求模态框数据加载
        show(number) {
            this.feedBackNumber = number
            this.needDialogVisible = true
        },
        // 关闭模态框
        closeChange(val) {
            this.needDialogVisible = val
            this.needForm = {
                id: null,
                resolutionCn: ''
            }
        },
        // 验证ID
        async toBugs() {
            try {
                const result = await FeedBack.getStoryDetail(this.needForm.id)
                if (result.success) {
                    const array = result.data.checkStoryList[0]
                    this.needForm.resolutionCn = array.planVersion
                    this.isClick = false
                    this.$message.success('Id存在，请绑定')
                } else {
                    this.$message.error(result.message)
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 取消按钮
        closeCancel() {
            this.needDialogVisible = false
            this.needForm = {
                id: null,
                resolutionCn: ''
            }
        },
        // 确认按钮
        async confirmClose(formName) {
            try {
                const result = await FeedBack.associateBugOrStory(this.needForm.id, this.feedBackNumber, 'story')
                if (result.success) {
                    this.$refs['needForm'].resetFields()
                    this.needForm = {
                        id: null,
                        resolutionCn: ''
                    }
                    this.$message.success('绑定成功')
                    this.needDialogVisible = false
                    // this.$router.go(0)
                    this.$emit('refreshPage')
                } else {
                    this.$message.error(result.message)
                }
            } catch (err) {
                console.log(err)
            }
        }
    }
}
</script>

<style scoped lang="less"></style>
